package com.property.demo.repository;

import com.property.demo.model.Home;
import com.property.demo.model.Repair;
import com.property.demo.model.Owner;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

@Repository
public interface RepairRepository extends JpaRepository<Repair, Long>, JpaSpecificationExecutor<Repair> {
    
    List<Repair> findByStatus(String status);
    
    List<Repair> findByType(String type);
    
    List<Repair> findByOwner(Owner owner);
    
    List<Repair> findByOwnerId(Long ownerId);
    
    List<Repair> findByHome(Home home);
    
    List<Repair> findByHomeId(Long homeId);

    @Query("SELECT COUNT(r) FROM Repair r WHERE r.reportTime >= :start AND r.reportTime <= :end")
    long countByReportTimeBetween(@Param("start") LocalDateTime start, @Param("end") LocalDateTime end);
} 